package com.abaaba.project2.service.wx.wxserviceimpl;

import com.abaaba.project2.bean.FeedBack;
import com.abaaba.project2.bean.User;
import com.abaaba.project2.bean.bo.wx.WxFeedbackBo;
import com.abaaba.project2.mapper.FeedBackMapper;
import com.abaaba.project2.mapper.UserMapper;
import com.abaaba.project2.service.WxFeedbackService;
import com.abaaba.project2.util.UserIdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {
    @Autowired
    FeedBackMapper feedBackMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public void saveFeedback(WxFeedbackBo wxFeedbackBo) {
        FeedBack feedBack = new FeedBack();
        feedBack.setAddTime(new Date());
        feedBack.setContent(wxFeedbackBo.getContent());
        feedBack.setDeleted(false);
        feedBack.setFeedType(wxFeedbackBo.getFeedType());
        feedBack.setHasPicture(wxFeedbackBo.getHasPicture());
        feedBack.setId(null);
        feedBack.setMobile(wxFeedbackBo.getMobile());
        feedBack.setStatus(0);
        feedBack.setUsername(userMapper.selectByPrimaryKey(UserIdUtil.getUserId()).getUsername());
        feedBack.setUpdateTime(new Date());

        if (feedBack.getHasPicture()) {
            feedBack.setPicUrls(wxFeedbackBo.getPicUrls()[0]);
        } else {
            feedBack.setPicUrls("");
        }

        feedBackMapper.insertSelective(feedBack);
    }
}
